if ( WScript.Arguments.Length == 0 )
{
	WScript.Echo( "Usage: <script> <rankings> <positions>" );
	WScript.Quit();
}

var fso = WScript.CreateObject( "Scripting.FileSystemObject" );

var fileRankings = fso.OpenTextFile( WScript.Arguments( 0 ) );
var iPlayer = 0;
var players = {};
while ( !fileRankings.AtEndOfStream )
{
	var fields = fileRankings.ReadLine().split( /\s*,\s*/i );

	iPlayer += 1;
	if ( iPlayer == 1 )
		continue;

	var prank = fields[ 0 ];
	var orank = fields[ 1 ];
	var player = fields[ 2 ];
	var age = fields[ 4 ];
	var pos = fields[ 5 ];

	if ( !players.hasOwnProperty( player ) )
	{
		players[ player ] = { name:player, positions:new Array(), pranks:new Array(), orank:orank, age:age };
		players[ player ].pranks.push( prank );
	}
	else
	{
		players[ player + '_' + iPlayer ] = { name:player, positions:new Array(), pranks:new Array(), orank:orank, age:age };
	}
}

var filePositions = fso.OpenTextFile( WScript.Arguments( 1 ) );
var iPlayer = 0;
while ( !filePositions.AtEndOfStream )
{
	var fields = filePositions.ReadLine().split( /\s*,\s*/i );
	var player = fields[ 0 ].split( /\s*\(/ )[ 0 ];
	fields.splice( 0, 1 );
	//WScript.Echo( player + ': ' + fields.join(',') );
	if ( !players.hasOwnProperty( player ) )
	{
		//WScript.Echo( 'Player not found: ' + player );
	}
	else
	{
		for ( pos in fields )
			if ( !/^(RP|LP)$/i.test( fields[ pos ] ) )
				players[ player ].positions.push( fields[ pos ] );
	}
}

WScript.Echo( 'ORank, Player, Age, Positions, PRank(s)' );
for ( player in players )
{
	WScript.Echo( players[ player ].orank + ', ' + player + ', ' + players[ player ].age + ', ' + players[ player ].positions.join( '/' ) + ', ' + players[ player ].pranks.join( '/' ) );
}